#include <iostream>
#include <iterator>
#include <vector>
#include <list>
#include <set>
#include <algorithm>

using std::cout;
using std::endl;
using std::ostream_iterator;
using std::back_inserter;
using std::back_insert_iterator;
using std::front_inserter;
using std::front_insert_iterator;
using std::inserter;
using std::insert_iterator;
using std::vector;
using std::list;
using std::set;
using std::copy;

void test()
{
    vector<int> vecNumber = {1, 3, 7, 9, 5};
    list<int> lstNumber = {4, 6, 8, 2, 10};
    //back_inserter的返回结果是back_insert_iterator类型，底层调用
    //了push_back
    copy(lstNumber.begin(), lstNumber.end(), 
         back_insert_iterator<vector<int>>(vecNumber));
    /* copy(lstNumber.begin(), lstNumber.end(), */ 
    /*      back_inserter(vecNumber)); */
    copy(vecNumber.begin(), vecNumber.end(), 
         ostream_iterator<int>(cout,  "  "));
    cout << endl;

    //想将vector中的元素插入到list的前面去
    cout << endl;
    //front_inserter的返回结果是front_insert_iterator类型，底层调用
    //了push_front
    copy(vecNumber.begin(), vecNumber.end(), 
         front_insert_iterator<list<int>>(lstNumber));
    /* copy(vecNumber.begin(), vecNumber.end(), */ 
    /*      front_inserter(lstNumber)); */
    copy(lstNumber.begin(), lstNumber.end(), 
         ostream_iterator<int>(cout,  "  "));
    cout << endl;

    cout << endl;
    //inserter的返回结果是insert_iterator类型，底层调用了insert
    set<int> setNumber = {1, 10, 40, 50, 90, 12};
    auto it = setNumber.begin();
    copy(vecNumber.begin(), vecNumber.end(), 
         inserter<set<int>>(setNumber, it));
    copy(setNumber.begin(), setNumber.end(), 
         ostream_iterator<int>(cout,  "  "));
    cout << endl;

}

int main(int argc, char *argv[])
{
    test();
    return 0;
}

